package com.mvp.shq.washer.entity;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.mvp.shq.washer.utils.DateUtils;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2017/9/1.
 */

public class Coupon {

    /**
     * id : 36f7f1cd1d9f49d38bc5dace8f0796de
     * couponType : 3   0 强力 1 标准 2 快速 3 单脱 4 通用
     * userId : 150dd9aebecc4525a6bd7817474f9327
     * status : 0
     * exipredTime : 2017-09-04 08:47:05
     * activeTime : 2017-09-01 08:47:05
     */

    private String id;
    private String couponType;
    private String userId;
    private String status;
    private String exipredTime;
    private String activeTime;
    private String showStatus;
    private String couponName;
    private boolean state;//是否过期
    private String time;//时间字符串

    public static Coupon objectFromData(String str) {

        return new Gson().fromJson(str, Coupon.class);
    }

    public static List<Coupon> arrayCouponFromData(String str) {

        Type listType = new TypeToken<ArrayList<Coupon>>() {
        }.getType();

        return new Gson().fromJson(str, listType);
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getCouponType() {
        return couponType;
    }

    public void setCouponType(String couponType) {
        this.couponType = couponType;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getExipredTime() {
        return exipredTime;
    }

    public void setExipredTime(String exipredTime) {
        this.exipredTime = exipredTime;
    }

    public String getActiveTime() {
        return activeTime;
    }

    public void setActiveTime(String activeTime) {
        this.activeTime = activeTime;
    }

    public String getShowStatus() {
        return showStatus;
    }

    public void setShowStatus(String showStatus) {
        this.showStatus = showStatus;
    }

    public String getCouponName() {
        String str = "";
        if ("0".equals(couponType)){
            str = "强力洗";
        }else if ("1".equals(couponType)){
            str = "标准洗";
        }else if ("2".equals(couponType)){
            str = "快速洗";
        }else if ("3".equals(couponType)){
            str = "单脱";
        }else if ("4".equals(couponType)){
            str = "通用";
        }
        str += "免单";
        return str;
    }

    public void setCouponName(String couponName) {
        this.couponName = couponName;
    }

    public boolean isState() {
        long time1 = DateUtils.StrToDate(exipredTime).getTime();
        long time2 = DateUtils.StrToDate(activeTime).getTime();
        Date date = new Date();
        long nowTime = date.getTime();
        if (nowTime > time2 && nowTime < time1){
            return true;
        }
        return false;
    }

    public void setState(boolean state) {
        this.state = state;
    }

    public String getTime() {
        String str = "";
        str += DateUtils.getTime(DateUtils.StrToDate(activeTime));
        str += "～";
        str += DateUtils.getTime(DateUtils.StrToDate(exipredTime));
        return str;
    }

    public void setTime(String time) {
        this.time = time;
    }
}
